package com.taichuan.keysupport.view.panel;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;

import com.taichuan.keysupport.Key;
import com.taichuan.keysupport.panel.PanelManager;
import com.taichuan.keysupport.panel.T16KeyBoardPanelManager;

public class T16KSPanelEditText extends TcPanelEditText {

    public T16KSPanelEditText(Context context) {
        super(context);
    }

    public T16KSPanelEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public T16KSPanelEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     * 定义一个 太川按键版 【16键】 设备专用的 EditText 按键事件监听回调对象
     */
    private final OnKeyListener tcKeyListener = new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == Key.Convert.KEYCODE_TAB
                    || keyCode == Key.Convert.KEYCODE_OK) {

            } else if (keyCode == Key.Convert.KEYCODE_LONG_XING
                    || keyCode == Key.Convert.KEYCODE_LONG_JING
                    || keyCode == Key.Convert.KEYCODE_LONG_0
                    || keyCode == Key.Convert.KEYCODE_DEFAULT_UNKONW) {

            } else if (keyCode == Key.Convert.KEYCODE_LONG_OK
                    || keyCode == Key.Convert.KEYCODE_LONG_DEL
                    || keyCode == Key.Convert.KEYCODE_LONG_TAB
                    || keyCode == Key.Convert.KEYCODE_LONG_GLZHX) {

            } else {
                if (panelManager != null) {
                    panelManager.onKeyDown(keyCode);
                }
                return true;
            }
            return false;
        }
    };

    @Override
    protected OnKeyListener setTcKeyListener() {
        return tcKeyListener;
    }

    @Override
    protected PanelManager initPanelManager(Context context) {
        return new T16KeyBoardPanelManager(context);
    }
}
